package com.lyzx.newboot2.day01.helloworld.model;

import java.math.BigDecimal;

public class User {
    private String name;
    private Apple apple;
    private Berry berry;
    private Mango mango;
    private BigDecimal totalMoney ;
    public User(String name, Apple apple, Berry berry, Mango mango) {
        this.name = name;
        this.apple = apple;
        this.berry = berry;
        this.mango = mango;
    }

    public BigDecimal getTotalMoney(){


        BigDecimal appleTotalMoney = null != apple ? apple.getTotalMoney(): new BigDecimal(0);
        BigDecimal berryTotalMoney = null != berry ? berry.getTotalMoney(): new BigDecimal(0);
        BigDecimal mangoTotalMoney = null != mango ? mango.getTotalMoney(): new BigDecimal(0);
        BigDecimal totalMoney = appleTotalMoney.add(berryTotalMoney).add(mangoTotalMoney);

        return totalMoney;
    }

    public String buyNames(){
        String appleName = null != apple ? apple.getName():"";
        String beeryName = null != berry ? berry.getName():"";
        String mangoName = null != mango ? mango.getName():"";
        return appleName+" "+beeryName+" "+mangoName;
    }

    public String say(BigDecimal totalMoney){
        return name+"购买了 ["+buyNames()+"] 共花费["+totalMoney+"]元" ;
    }

    public String say(){
        return name+"购买了 ["+buyNames()+"] 共花费["+getTotalMoney()+"]元" ;
    }



}
